package com.supor.aiot.common.ui.activity;

import android.content.Intent;
import android.os.Bundle;

import com.android.baseconfig.common.utils.GsonUtil;
import com.android.baseconfig.common.utils.Logc;
import com.supor.aiot.common.R;
import com.supor.aiot.common.app.SuporPresenter;
import com.supor.aiot.common.base.BaseNfcActivity;
import com.supor.aiot.common.entity.RecordBean;
import com.supor.aiot.common.helper.GlobalDataCache;
import com.supor.aiot.common.helper.NFCHelper;

/**
 * ---------------------------------------------------------------- <br>
 * Copyright (C) 2014-2020, by het, Shenzhen, All rights reserved.  <br>
 * ---------------------------------------------------------------- <br>
 * <p>
 * 描述: 触碰NFC时弹出页面，页面为透明，数据交互完销毁页面 <br>
 * 作者: lei <br>
 * 日期: 2020/10/17 <br>
 */
public class SuporNFCActivity extends BaseNfcActivity {

    @Override
    protected int resourceId() {
        return 0;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_nfc);
        process(getIntent());
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);

        // 在onNewIntent中处理由NFC设备传递过来的intent
        process(intent);
    }

    private void process(Intent intent) {
        RecordBean recordBean = NFCHelper.getInstance().processIntent(intent);
        if (recordBean == null) {
            Logc.d("record bean is null");
            // RxBus2.getInstance().post(RecordBean.class.getName(), recordBean);
            // if (SuporApplication.getInstance().getCurrentActivity() instanceof NFCGuideActivity) {
            //     NFCHelper.getInstance().writeNfcA(intent,
            //             BuildHelper.buildWiFiData(DataCache.CURRENT_SSID, DataCache.CURRENT_PWD));
            // }
            return;
        }
        GlobalDataCache.NFC_PARAMS = GsonUtil.getInstance().toJson(recordBean);
        GlobalDataCache.recordBean = recordBean;
        SuporPresenter.getInstance().startDisplay(this, recordBean);
    }

    @Override
    protected boolean isUseBlackFontWithStatusBar() {
        return false;
    }

    @Override
    public void finish() {
        super.finish();
        overridePendingTransition(0, 0);
    }
}